package com.jiangyao.controller;


import com.github.pagehelper.PageInfo;
import com.jiangyao.common.ApiResult;
import com.jiangyao.common.enums.IndustryEnum;
import com.jiangyao.common.exception.ServerException;
import com.jiangyao.model.dto.BaseDTO;
import com.jiangyao.model.dto.backend.*;
import com.jiangyao.model.entity.Job;
import com.jiangyao.model.vo.JobVo;
import com.jiangyao.model.vo.backend.IndustryVO;
import com.jiangyao.service.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.jiangyao.controller.BaseController;

import java.util.ArrayList;

/**
 * <p>
 * 职位 前端控制器
 * </p>
 *
 * @author zhoushuangxiang
 * @since 2020-08-12
 */
@RestController
@RequestMapping("/job")
@Api(tags = "后台职位相关接口")
public class JobController extends BaseController {

    @Autowired
    private JobService jobService;

    /**
     * 发布职位
     * @param addJobDTO
     * @return
     */
    @ApiOperation(value = "发布职位")
    @PostMapping("/addJob")
    public ApiResult addJob(@Validated({AddJobDTO.Add.class}) @RequestBody AddJobDTO addJobDTO){
        try {
            return ApiResult.success(jobService.addJob(addJobDTO));
        } catch (ServerException e) {
            return ApiResult.error(e.getCode(),e.getMessage());
        }
    }

    @ApiOperation(value = "获取职位详情")
    @GetMapping("/getJobDetail")
    public ApiResult<Job> getJobDetail(@RequestParam("jobId") Integer jobId){
        return ApiResult.success(jobService.getBkJobDetail(jobId));
    }

    /**
     * 修改职位
     * @param addJobDTO
     * @return
     */
    @PostMapping("/editJob")
    @ApiOperation(value = "修改职位")
    public ApiResult editJob(@Validated({AddJobDTO.Edit.class}) @RequestBody AddJobDTO addJobDTO){
        try {
            return ApiResult.success(jobService.editJob(addJobDTO));
        } catch (ServerException e) {
            return ApiResult.error(e.getCode(),e.getMessage());
        }
    }

    /**
     * 获取职位列表
     * @param jobListDTO
     * @return
     */
    @PostMapping("/getJobList")
    @ApiOperation(value = "获取职位列表")
    public ApiResult<PageInfo<JobVo>> getJobList(@Validated @RequestBody JobListDTO jobListDTO){
        try {
            return ApiResult.success(jobService.getJobList(jobListDTO));
        } catch (ServerException e) {
            return ApiResult.error(e.getCode(),e.getMessage());
        }
    }

    @PostMapping("/editJobSattus")
    @ApiOperation(value = "修改职位状态")
    public ApiResult editJobStatus(@Validated(BaseDTO.Edit.class)@RequestBody EditJobStatusDto editJobStatusDto){
        try {
            jobService.editJobStatus(editJobStatusDto);
            return ApiResult.success("修改职位状态成功");
        } catch (Exception e) {
            return ApiResult.error("修改职位状态失败");
        }
    }


    @PostMapping("/editJobAuditSattus")
    @ApiOperation(value = "修改职位审核状态")
    public ApiResult editJobAuditSattus(@Validated(BaseDTO.Edit.class)@RequestBody EditJobAuditStatusDto dto){
        try {
            jobService.editJobAuditStatus(dto);
            return ApiResult.success("修改审核状态成功");
        } catch (Exception e) {
            return ApiResult.error("修改审核状态失败");
        }
    }

}

